package com.example.test

import android.util.Log
import androidx.lifecycle.ViewModel
import com.example.test.qtnet.ApiService
import com.example.test.qtnet.ApiWrapper
import com.example.test.support.QiantoonNetworkApi
import com.example.test.support.errorhandler.ExceptionHandle
import com.example.test.qtnet.request

/**
 * @Package com.example.test
 * @ClassName TestViewModel
 * @Author caostgrace
 * @Date 2021/4/8
 * @Email liaobing@qiantoon.com
 * @Desc
 */
class TestViewModel : ViewModel() {

    val api = ApiWrapper()

    fun test() {

        request<List<InvoiceTitleBean>> {

            loader {
                api.queryInvoiceTitleList("1","10")
            }
            onError {
                it.printStackTrace()
                if(it is ExceptionHandle.ResponseThrowable){
                    Log.e("======>",it.errorMessage)
                }
                false
            }
            onSuccess {
                Log.e("====>",it.toString())
                Log.e("====>","${it.size}")
            }
        }


    }

    fun test1(){
        request<List<InvoiceTitleBean>> {
            loader {
                QiantoonNetworkApi.getService(ApiService::class.java)
                        .queryInvoiceTitleList("1","10")
            }
            onError {
                it.printStackTrace()
                if(it is ExceptionHandle.ResponseThrowable){
                    Log.e("======>",it.errorMessage)
                }
                true
            }
            onSuccess {
                Log.e("====>",it.toString())
                Log.e("====>","${it.size}")
            }
        }
    }

}